# 模型融合

import pandas as pd
import os

csv_files = ["../submit/submit_model_weight.04-0.9031_equalize_hist_bin.hdf5.csv",
             "../submit/submit_model_weight.14-0.8929_balance_bin.hdf5.csv"]

final_res_path = '../submit/balance_equalize_merge.csv'

w_list = [0.5, 0.5]
w_list = [w / sum(w_list) for w in w_list]

# 获取index与probability
file0 = pd.read_csv(csv_files[0])
file_name = list(file0.iloc[:, 0])
probability = {key: [] for key in list(file0.columns)[1:-1]}

# 每一个csv文件的原始数据
csv_data = []
for csv in csv_files:
    csv_data.append(pd.read_csv(csv))

# 每行
for i in range(len(file_name)):
    # 每列
    for key in probability:
        pro = 0
        # 每文件
        for j in range(len(csv_data)):
            pro += csv_data[j][key][i] * w_list[j]
        pro = round(pro, 5)
        probability[key].append(pro)
probability["real"] = list(file0["real"])

dataframe = pd.DataFrame(data=probability, index=file_name)
dataframe.to_csv(final_res_path)
print(final_res_path, "融合完成")
